package com.hngy.xpq.android_practice.user_main;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.hngy.xpq.android_practice.R;
import com.hngy.xpq.android_practice.bean.User;
import com.hngy.xpq.android_practice.database.SQLiteUser;
import com.hngy.xpq.android_practice.http.TcpClient;

public class UserUpdateKey extends AppCompatActivity {

    EditText name,phone;
    Button yz;
    SQLiteUser sqLiteUser;

    private void UserUpdate() {
        name = findViewById(R.id.wj_xpq_name);
        phone = findViewById(R.id.wj_xpq_phone);
        yz = findViewById(R.id.wj_button);
    }

    public void IndexToast(String text){
        Toast.makeText(UserUpdateKey.this,text,Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_zhaohui_update_key1);
        UserUpdate();
        sqLiteUser = new SQLiteUser(this);
        yz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String update_name = name.getText().toString();
                String update_phone = phone.getText().toString();
                String information = "XG001//" + update_name + "//" + update_phone;
                String a = new TcpClient().Transits(information);
                if (TextUtils.isEmpty(name.getText())){
                    IndexToast("用户名不能为空!!");
                } else if (TextUtils.isEmpty(phone.getText())){
                    IndexToast("电话号码不能为空!!");
                } else if (a.equals("信息验证成功!")){
                    Intent intent = new Intent(UserUpdateKey.this,SUserUpdateKey.class);
                    intent.putExtra("name",update_name);
                    IndexToast("信息验证成功!!");
                    startActivity(intent);
                    finish();
                } else {
                    IndexToast(a);
                }
            }
        });
    }


}